package com.hpeu_01.day0113.homework;

/**
 * 第二题：求出“hijavahehejavahejava”字符串里面包含几个“java”字符串。
 */
public class HomeWork04 {
    public static void main(String[] args) {
        String str="hijavahehejavahejava";
        String s = "java";
        int sum = 0;
        for (int i =0;i<str.length()-s.length();i++){
            if (str.substring(i,i+s.length()).equalsIgnoreCase(s)){
                sum++;
            }
        }
        if (str.substring(str.length()-s.length()).equalsIgnoreCase(s)){
            sum+=1;
        }
        System.out.println("一共包含了"+sum+"个字符串");
        System.out.println();
        int n=0;
        for (int i=0;i<str.length();i++){
             int x = str.indexOf("java", i);
            if (x==i){
                n++;
            }
        }
        System.out.println("一共包含了"+n+"个字符串");
    }
}
